import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/home/analysis/get_company_device_list_entity.dart';

class OffController extends GetxController {
  /// 列表刷新key
  final GlobalKey<CustomEasyRefreshListState> globalKey = GlobalKey();
  RxString searchX = ''.obs;

  /// 获取数据
  Future<List<GetCompanyDeviceListEntity>> getCompanyDeviceListEntity(int index, int size,
      {String? search}) async {
    final res =
    await HttpUtil().generateGetRequest<List<GetCompanyDeviceListEntity>>(
      Interface.getCompanyDeviceList,
      queryParameters: {
        // 'pageNum': index,
        // 'pageSize': size,
        'deviceName': searchX.value, //	设备名称
        'onlineStatus': 0, // onlineStatus=0离线 =1在线
        'companyId': Get.arguments['id'], // 公司id
      },
    ).execute();
    List<GetCompanyDeviceListEntity>? list = [];
    res.onSuccess((result) {
      if (result.data != null) {
        list = result.data;
      }
    });
    return list ?? [];
    // [
    // '主坝干滩监测01',
    // '主坝干滩监测02',
    // ];
  }

  void refreshPage() {
    globalKey.currentState?.onRefresh();
  }
}
